//
//  KnowTableViewCell.swift
//  sinofert_Swift
//
//  Created by enway-wk on 2017/6/20.
//  Copyright © 2017年 enway-wk. All rights reserved.
//

import UIKit
import SDWebImage

class KnowTableViewCell: UITableViewCell {
    
    var headImage:UIImageView?
    var nameLabel:UILabel!
    var publishTimeLabel:UILabel!
    var questionTitleLabel:UILabel!
    var questionTextLabel:UILabel!
    var regionImage:UIImageView!
    var regionLabel:UILabel!
    var replyImage:UIImageView!
    var replyNumLabel:UILabel!
    var userInfo = UserInfoModel()
    var lineView:UIImageView!//分割线
    
    var model:KnowModel{
        set{
            userInfo.yy_modelSet(with: newValue.userinfo!)
            headImage?.sd_setImage(with: URL(string:userInfo.photo!), placeholderImage:UIImage.init(named: "nongyibao.png"))
            nameLabel.text = userInfo.nikeName
            publishTimeLabel.text = newValue.publishtime
            questionTitleLabel.text = newValue.questiontitle
            questionTextLabel.text = newValue.questiontext
        }
        get{
            return self.model
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        createCell()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func createCell(){
        //用户头像
        headImage = UIImageView()
        headImage?.layer.masksToBounds = true
        headImage?.layer.cornerRadius = 15
        
        //用户名
        nameLabel = UILabel()
        nameLabel.font = UIFont.systemFont(ofSize: 12)
        
        //问题发布时间
        publishTimeLabel = UILabel()
        publishTimeLabel.font = UIFont.systemFont(ofSize: 12)
        publishTimeLabel.textColor = UIColor.gray
        
        
        //问题标题
        questionTitleLabel = UILabel()
        questionTitleLabel.font = UIFont.systemFont(ofSize: 14)
        
        //问题内容
        questionTextLabel = UILabel()
        questionTextLabel.font = UIFont.systemFont(ofSize: 12)
        
        
        //分割线
        lineView = UIImageView()
        lineView.backgroundColor = UIColor.init(colorLiteralRed: 245/255.0, green: 245/255.0, blue: 245/255.0, alpha: 1)
        
        self.contentView.addSubview(headImage!)
        self.contentView.addSubview(nameLabel)
        self.contentView.addSubview(publishTimeLabel)
        self.contentView.addSubview(questionTitleLabel)
        self.contentView.addSubview(questionTextLabel)
        self.contentView.addSubview(lineView)
        
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        headImage?.frame = CGRect(x: 10, y: 10, width: 30, height: 30)
        nameLabel.frame = CGRect(x:(headImage?.frame.maxX)!+5, y: (headImage?.frame.origin.y)!, width:200 , height: 10)
        publishTimeLabel.frame = CGRect(x: nameLabel.frame.origin.x, y: nameLabel.frame.maxY+5, width: 200, height: 10)
        questionTitleLabel.frame = CGRect(x: 10, y: (headImage?.frame.maxY)!+10, width: SCREEN_WIETH-20, height: 30)
        questionTextLabel.frame = CGRect(x: 10, y: questionTitleLabel.frame.maxY+10, width: SCREEN_WIETH, height: 30)
        lineView.frame = CGRect(x: 0, y: self.contentView.frame.height-2, width: SCREEN_WIETH, height: 2)
    }
    
    
}
